package com.xayy.health.core.antlr4.utils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import cn.kawins.base.utils.CollUtil;

/**
 * @author Nie
 * @version V1.0
 * @date 2023/8/17 10:24
 */
public class Golabl {
    /**
     * 正常计算的指标缓存
     */
    public static final Map<String, Map<String, Double>> PARAM_VALUE = new ConcurrentHashMap<>();
    /**
     * 性能指标性计算缓存
     */
    public static final Map<String, Map<String, Double>> XN_VALUE = new ConcurrentHashMap<>();

    /**
     * 设置指标的分值缓存
     * 
     * @param satCode
     *            卫星id
     * @param name
     *            指标代号名称
     * @param value
     *            指标值
     */
    public static void setValue(String satCode, String name, Double value) {
        Map<String, Double> satMap = PARAM_VALUE.get(satCode);
        if (CollUtil.isEmpty(satMap))
            satMap = new ConcurrentHashMap<>(10);
        satMap.put(name, value);
        PARAM_VALUE.put(satCode, satMap);
    }

    /**
     * 设置性能指标性指标的分值缓存
     *
     * @param satCode
     *            卫星id
     * @param name
     *            指标代号名称
     * @param value
     *            指标值
     */
    public static void setXnValue(String satCode, String name, Double value) {
        Map<String, Double> satMap = XN_VALUE.get(satCode);
        if (CollUtil.isEmpty(satMap))
            satMap = new ConcurrentHashMap<>(10);
        satMap.put(name, value);
        XN_VALUE.put(satCode, satMap);
    }

    /**
     * 获取指标分值缓存
     * 
     * @param satCode
     *            卫星id
     * @param name
     *            指标代号名称
     * @return 结果
     */
    public static Double getValue(String satCode, String name) {
        Double value = null;
        Map<String, Double> satMap = PARAM_VALUE.get(satCode);
        if (CollUtil.isEmpty(satMap))
            return value;
        value = satMap.get(name);
        return value;
    }

    /**
     * 获取性能指标性指标的分值缓存
     *
     * @param satCode
     *            卫星id
     * @param name
     *            指标代号名称
     * @return 结果
     */
    public static Double getXnValue(String satCode, String name) {
        Double value = null;
        Map<String, Double> satMap = XN_VALUE.get(satCode);
        if (CollUtil.isEmpty(satMap))
            return value;
        value = satMap.get(name);
        return value;
    }

    public static void clear(String satCode) {
        PARAM_VALUE.put(satCode, new ConcurrentHashMap<>(10));
    }

    public static void clearXn(String satCode) {
        XN_VALUE.put(satCode, new ConcurrentHashMap<>(10));
    }

}
